package com.mysoft.gfyx.marketdevelop.mip.dto;

import com.alibaba.fastjson.JSONArray;
import com.mysoft.framework.common.exception.BusinessLogicException;
import com.mysoft.framework.modeling.dto.Filter;
import com.mysoft.gfyx.common.util.MyStringUtil;
import com.mysoft.gfyx.marketdevelop.service.LabelService;
import com.mysoft.gfyx.marketdevelop.service.impl.LabelServiceImp;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Data
public class SearchDeveloperRequestDto extends SearchBaseRequestDto {
    private String keyword;
    private String province_code;
    private String city_code;
    private String company_type;
    private String project_type;
    private String land_type;

    private String developer_activity_label;
    private String developer_top_100_label;
    private String is_new_area_expand_label;
    private String is_new_decorate_expand_label;
    private String is_new_land_usage_expand_label;
    private String high_project_customers_label;
    private String is_ycg_certification;
    private String is_ycg_offline_business_connect;
    //行业分类第3级
    private String industry_category_middle;

    private int page;
    private int pageSize;

    public static final String FILTER_DEVELOPER_NAME = "developer_name";

    public static final String FILTER_DEVELOPER_TAGS = "tags_set";

    public static final String FILTER_DEVELOPER_LEVEL_TAG = "company_level_tag";

    protected void setFilterByField(String field, String operatorType, Object value) {
        switch (field) {
            case FILTER_DEVELOPER_NAME:
                this.setKeyword(value.toString());
                break;
            case FILTER_DEVELOPER_LEVEL_TAG:
                switch (value.toString()) {
                    case "developer_activity_label":
                        this.setDeveloper_activity_label("活跃");
                        break;
                    case "is_ycg_certification":
                        this.setIs_ycg_certification("平台认证");
                        break;
                    case "is_ycg_offline_business_connect":
                        this.setIs_ycg_offline_business_connect("供需对接会");
                        break;
                    default:
                        throw new BusinessLogicException("未定义的标签" + value.toString());
                }
                break;
            case FILTER_DEVELOPER_TAGS:
                switch (value.toString()) {
                    case "developer_top_100_label":
                        this.setDeveloper_top_100_label("地产百强");
                        break;
                    case "is_new_decorate_expand_label":
                        this.setIs_new_decorate_expand_label("新精装客群");
                        break;
                    case "is_new_land_usage_expand_label":
                        this.setIs_new_land_usage_expand_label("新住宅客群");
                        break;
                    case "is_new_area_expand_label":
                        this.setIs_new_area_expand_label("新区域拓展");
                        break;
                    case "high_project_customers_label":
                        this.setHigh_project_customers_label("高端项目客群");
                        break;
                    default:
                        throw new BusinessLogicException("未定义的标签" + value.toString());
                }
                break;
            case "land_usage":
                this.setLand_type(MyStringUtil.TranArrayToStr(operatorType, value).toString());
                break;
            case "industry_category":
                List<Object> industryCategory = new ArrayList<>();
                if (value instanceof ArrayList<?>) {
                    for (Object o : (List<?>) value) {
                        industryCategory.add(o);
                    }
                }
                //三级
                List<Object> industryCategoryMiddle = new ArrayList<>();
                industryCategory.forEach(p -> {
                    JSONArray item = JSONArray.parseArray(p.toString());
                    industryCategoryMiddle.add(item.get(2));
                });
                String industryCategoryStr = industryCategoryMiddle.stream().map(String::valueOf).collect(Collectors.joining(","));
                this.setIndustry_category_middle(industryCategoryStr);
                break;
            default:
                this.dynamicSetProperty(field, value);
        }
    }
}
